package com.tigerhhzz.springcloud.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.tigerhhzz.springcloud.service.PaymentService;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author tigerhhzz
 * @date 2023/4/15 9:18
 */
@Service
public class PaymentServiceImpl implements PaymentService {

    @Override
    public String getPaymentInfo_OK(Integer id) {
        return "当前线程池名称： "+Thread.currentThread().getName()+"----getPaymentInfo_OK----,id: "+id;
    }

    @Override
    @HystrixCommand(fallbackMethod = "getPaymentInfo_ErrorHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "5000")
    })
    public String getPaymentInfo_Error(Integer id) {
        //System.out.println(Thread.currentThread().getName()+"-----------error----------"+id);
        int timeout = 3;
        //int age = 10/0;
        try {
            TimeUnit.SECONDS.sleep(timeout);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "当前线程池名称： "+Thread.currentThread().getName()+"-----getPaymentInfo_Error----ERROR----"+id;
    }

    /*fallback服务降级后的兜底方法*/
    public String getPaymentInfo_ErrorHandler(Integer id) {
        return Thread.currentThread().getName()+"-----8001 allback服务降级后的兜底方法----超时或异常------getPaymentInfo_ErrorHandler----ERROR----"+id;
    }

    @Override
    public String paymentCircuitBreaker(Integer id) {
        return null;
    }



}
